package com.twu.biblioteca.Models;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: spacetime
 * Date: 8/9/13
 * Time: 5:51 AM
 * Represents a Library of Books
 */
public class BookLibrary {

    private ArrayList<Book> bookArrayList = new ArrayList<Book>();

    public String getStringOfAllBooks() {
        StringBuilder allBooks = new StringBuilder();
        int listIDForIdentifyingBook = 0;
        for (Book book : bookArrayList) {
            allBooks.append(listIDForIdentifyingBook + 1);
            allBooks.append(". " + book.getTitle());
            allBooks.append("\n");
            listIDForIdentifyingBook++;
        }
        return allBooks.toString();
    }

    public void addBook(Book book) {
        this.bookArrayList.add(book);
    }

    public String checkMembershipDetails() {
        return "Please talk to a Librarian. Thank you.";
    }

    public Book getBookWithID(int id) {
        if (id <= bookArrayList.size() && id > 0)
            return bookArrayList.get(id-1);
        return null;
    }

    public static void addTitleAsBookToLibrary(BookLibrary bookLibrary, String title) {
        Book book = new Book(title);
        bookLibrary.addBook(book);
    }
}
